package com.bawei.database.db

import androidx.room.DeleteColumn
import androidx.room.RenameColumn
import androidx.room.RenameTable
import androidx.room.migration.AutoMigrationSpec
import androidx.sqlite.db.SupportSQLiteDatabase


/**
 * 修改表名
 */
@RenameTable(fromTableName = "user_info_table", toTableName = "user_info")
class UserInfoAutoMigration: AutoMigrationSpec

/**
 * 修改表中的字段
 * 注意：改修改实体里的字段，然后使用下面的升级配置修改旧数据库中字段名
 */
@RenameColumn(tableName = "user_info", fromColumnName = "username", toColumnName = "name")
class UserInfoColumnAutoMigration: AutoMigrationSpec

/**
 * 删除表中的字段
 */
@DeleteColumn(tableName = "user_info_table", columnName = "ctime")
class UserInfoDeleteColumnAutoMigration: AutoMigrationSpec{
    override fun onPostMigrate(database: SupportSQLiteDatabase) {
        super.onPostMigrate(database)
//        database.execSQL("""
//                CREATE TABLE new_Song (
//                    id INTEGER PRIMARY KEY NOT NULL,
//                    name TEXT,
//                    tag TEXT NOT NULL DEFAULT ''
//                )
//                """.trimIndent())
//        database.execSQL("""
//                INSERT INTO new_Song (id, name, tag)
//                SELECT id, name, tag FROM Song
//                """.trimIndent())
//        database.execSQL("DROP TABLE Song")
//        database.execSQL("ALTER TABLE new_Song RENAME TO Song")
    }
}

